import { UploadService } from "./upload.service";
import { ApiTags } from "@nestjs/swagger";
import { Controller, Inject, Post, UploadedFile, UseInterceptors } from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { KwFile } from "../interfaces";

@ApiTags('文件上传')
@Controller('/upload')
export class UploadController {

  @Inject()
  private uploadService: UploadService;

  @Post('file')
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile() file: KwFile) {
    const filename = await this.uploadService.uploadFile(file);
    return filename;
  }

  @Post('files')
  @UseInterceptors(FileInterceptor('files'))
  async uploadFiles(@UploadedFile() files: Array<KwFile>) {
    const filenames = await this.uploadService.uploadFiles(files);
    return filenames;
  }
}